<template>
    <el-container>
        <el-header>
            <div class="right-panel-search">
                <div class="search-input">计划完工</div>
                    <el-date-picker v-model="search.time_range" type="daterange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" :size="size" style="width:220px" />
                <div class="search-input">订单号</div>
                <el-input v-model="search.keyword" placeholder="请输入订单号" />
                <el-button type="primary" icon="el-icon-search" @click="upsearch">搜索</el-button>
            </div>
        </el-header>
        <el-main class="nopadding">
            <scTable ref="table" :apiObj="apiObj" stripe remoteSort remoteFilter border :params="query">
                <el-table-column type="selection" width="40"></el-table-column>
                <!-- <el-table-column fixed type="index" align="center" width="50"></el-table-column> -->
                <el-table-column fixed label="订单号" align="center" width="160">
                    <template #default="{row}">
                        <div>{{row.order_no}}</div>
                        <div>{{row.create_time}}</div>
                    </template>
                </el-table-column>
                <el-table-column label="商品信息" fixed prop="goods" align="center" width="300">
                    <template #default="{row}">
                        <div class="shopInfo" v-if="row.goods">
                            <el-image class="img" :src="row.goods.goods_image" :preview-src-list="row.goods.goods_image_item" :initial-index="0" fit="cover" preview-teleported="true" />
                            <div class="right">
                                <div>工厂货号：{{row.factory_number}}</div>
                                <div>批次号：{{row.batch_number}}</div>
                                <div>SKC：{{row.skc}}</div>
                                <div>商品品牌：{{row.brand_name}}</div>
                                <div>客户：{{row.custom_name}}</div>
                                <div>颜色：{{row.goods.colour}}</div>
                                <div v-if="row.sizeCate">商品类别：{{row.sizeCate.title}}</div>
                            </div>
                        </div>
                    </template>
                </el-table-column>
                <el-table-column fixed label="尺码" align="center">
                    <template #default="{row}">
                        <div v-for="(item,index) in row.orderDetail" :key="index">
                            {{item.goods_size}}
                        </div>
                    </template>
                </el-table-column>
                <el-table-column fixed label="数量" prop="total_count" align="center">
                    <template #default="{row}">
                        <div v-for="(item,index) in row.orderDetail" :key="index">
                            {{item.num}}
                        </div>
                    </template>
                </el-table-column>
                <el-table-column label="订单标签" align="center" width="100">
                    <template #default="scope">
                        <el-tag v-if="scope.row.order_label==1" type="danger">加急</el-tag>
                        <el-tag v-else type="success">正常</el-tag>
                    </template>
                </el-table-column>
                <el-table-column label="针种" prop="needle_seed_name" align="center"></el-table-column>
                <el-table-column label="毛种" prop="wool_seed_name" align="center"></el-table-column>
                <el-table-column label="生产交期" prop="deliver_time" align="center"></el-table-column>
                <el-table-column label="下单人" prop="creator_name" align="center"></el-table-column>
                <el-table-column label="制单人" prop="maintenance_name" align="center"></el-table-column>
                <el-table-column label="操作" fixed="right" align="center" width="110">
                    <template #default="scope">
                        <el-button-group style="display:flex;flex-direction:column">
                            <el-button text type="primary" size="small" @click="goDetail(scope.row, scope.$index)" v-auth="'produce.perfect'">生产单详情</el-button>
                            <el-button text type="primary" size="small" @click="goPer(scope.row, scope.$index)">完善生产单</el-button>
                            <el-button text type="primary" size="small" @click="table_edit(scope.row, scope.$index)" v-auth="'produce.edit'">修改</el-button>
                            <el-popconfirm title="确定删除吗？" @confirm="table_del(scope.row, scope.$index)" v-auth="'produce.delete'">
                                <template #reference>
                                    <el-button text type="danger" size="small">删除</el-button>
                                </template>
                            </el-popconfirm>
                        </el-button-group>
                    </template>
                </el-table-column>
            </scTable>
        </el-main>
    </el-container>
    <!-- <add-pro v-if="dialog.save" ref="addDialog" @success="handleSuccess" @closed="dialog.save = false" draggable></add-pro> -->
    <!-- <process v-if="dialog.proSave" ref="proDialog" @success="handleSuccess" @closed="dialog.proSave = false" draggable></process> -->
    <perfect v-if="dialog.perSave" ref="perDialog" @success="handleSuccess" @closed="dialog.perSave = false" draggable></perfect>
    <detail v-if="dialog.detSave" ref="detDialog" @success="handleSuccess" @closed="dialog.detSave = false" draggable></detail>
</template>
<script>
import Detail from './detail.vue';
// import addPro from './addPro';
// import Process from './process';
import Perfect from './perfect';

export default {
//   components: { addPro,Process,Perfect },
components: { Perfect,Detail },
	name: 'user',
	data() {
		return {
            dialog:{
                // save:false,
                // proSave:false,
                perSave:false,
                detail:false
            },
			groupFilterText: '',
			group: [],
			apiObj: this.$API.produce.getProduce.lists,
            query:{
                planned_speed:0
            },
			selection: [],
			search: {
				time_range: null,
				keyword: null,
			},
			//所需数据选项
            settlementList: [],
		}
	},
	watch: {
		groupFilterText(val) {
			this.$refs.group.filter(val);
		}
	},
	mounted() {},
	methods: {
		//添加
		add() {
			this.dialog.save = true
			this.$nextTick(() => {
				this.$refs.addDialog.open('add')
			})
		},
        // 生产
        // goPro() {
		// 	this.dialog.proSave = true
		// 	this.$nextTick(() => {
		// 		this.$refs.proDialog.open('add')
		// 	})
		// },
        // 完善生产单
        goPer(row) {
			this.dialog.perSave = true
			this.$nextTick(() => {
				this.$refs.perDialog.open('add').setData(row)
			})
		},
        // 详情
        goDetail(row) {
			this.dialog.detSave = true
			this.$nextTick(() => {
				this.$refs.detDialog.open('add').setData(row)
			})
		},
		//编辑
		table_edit(row) {
			this.dialog.perSave = true
			this.$nextTick(() => {
				this.$refs.perDialog.open('edit').setData(row)
			})
		},
		//删除
		async table_del(row, index) {
			var reqData = { id: row.id }
			var res = await this.$API.produce.getProduce.delete.post(reqData);
			if (res.code == 1) {
				//这里选择刷新整个表格 OR 插入/编辑现有表格数据
				this.$refs.table.tableData.splice(index, 1);
                this.$refs.table.refresh()
				this.$message.success("删除成功")
			} else {
				this.$alert(res.message, "提示", { type: 'error' })
			}
		},
		//搜索
		upsearch() {
			this.$refs.table.upData(this.search)
		},
		//本地更新数据
		handleSuccess(data, mode) {
			if (mode == 'add') {
				this.$refs.table.refresh()
			} else if (mode == 'edit') {
				this.$refs.table.refresh()
			} else if (mode == 'set') {
				this.$refs.table.refresh()
			}
		}
	}
}
</script>

<style>
.search-input {
	width: auto;
	font-size: 14px;
}
</style>